package com.weigj.model;

import java.util.List;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

public class ReserveHour extends Model<ReserveHour>{
	public static final ReserveHour dao = new ReserveHour();
	/**
	 * 根据会员Id查询预订单信息
	 * @param clientId 会员Id
	 * @param reserveState 预订单状态 0为取消 1为预定 2为完成 空则为全部
	 * @return
	 */
	public List<ReserveHour> queryRHByState(Long clientId,Integer reserveState){
		
		String sql="select * from app_reserveHour r where r.clientId=?";
		if(reserveState!=null){
			sql+=" and r.reserveState=?";
			return dao.find(sql,clientId, reserveState);
		}
		return dao.find(sql, clientId);
	}
	/**根据预定单编号查询预定单
	 * @param num 预定单编号
	 * @return
	 */
	public ReserveHour queryOneByNum(String num){
		ReserveHour rh = new ReserveHour();
		try
		{
			Preconditions.checkArgument(!Strings.isNullOrEmpty(num));
		} catch (Exception e)
		{
			System.out.println("预定单编号为空");
			return null;
		}
		String sql = "select * from app_reserveHour r where r.reserveNo=?";
		rh=dao.findFirst(sql,num);
		return rh;
	}
	/**根据预定单编号查询合同车辆信息
	 * @param num
	 * @return
	 */
	public CarInfo queryCarInfoByNum(String num){
		return CarInfo.dao.queryCarInfo(dao.queryOneByNum(num).getStr("CARNUM"));
	}
	/**
	 * 根据预订单Id查询合同
	 * @param id
	 * @return
	 */
	public Record queryOneCont(Long id){
		String sql="select h.* from app_hourcontract h where h.orderid=? and h.conState=1";
		return Db.findFirst(sql,id);
	}
}
